#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
@author:  runyuanye
@contact: yerunyuan@163.com
"""

import argparse
import os
import sys
import shutil

sys.path.append('.')

"""
   拷贝相同人脸的视频
"""


def main():
    parser = argparse.ArgumentParser(description="Copy Same Face Video")
    parser.add_argument(
        "--video_dir", default="/rootfs/media/kasim/DataSet/RecordEx", help="path to video dir", type=str
    )
    parser.add_argument(
        "--file_list", default="/rootfs/media/kasim/DataSet/FaceCropImage/SelectFaceVideo.txt", help="path to file list", type=str
    )
    parser.add_argument(
        "--output_dir", default="/rootfs/media/kasim/DataSet/FaceVideo", help="path to output", type=str
    )
    args = parser.parse_args()

    output_dir = args.output_dir
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    file_count = 0
    with open(args.file_list, 'r') as file:
        for line in file.readlines():
            file_count += 1
            print('Copy Face Count: {}'.format(file_count))

            file_name = line.strip()
            src_file_path = os.path.join(args.video_dir, file_name)
            if not os.path.exists(src_file_path):
                continue
            dst_file_path = os.path.join(args.output_dir, file_name)

            out_path = os.path.dirname(dst_file_path)
            if not os.path.exists(out_path):
                os.makedirs(out_path)
            shutil.copy(src_file_path, dst_file_path)

        print('Copy Face Count: {}'.format(file_count))

    os.system('chmod a+wr {} -Rf'.format(output_dir))
    print('finish!')


if __name__ == '__main__':
    main()

